<!--#
layout("/layouts/platform.html"){
#-->
<header class="header navbar bg-white shadow">
    <div class="btn-group tool-button">
        <a class="btn btn-primary navbar-btn" href="${base}/platform/wx/conf/menu/add/${wxid}" data-pjax><i class="ti-plus"></i>${msg['wx.menu.column.addmenu']} </a>
        <a href="${base}/platform/wx/conf/menu/index/${wxid}" data-pjax id="_reload"></a>
    </div>

    <div class="btn-group">
        <div >
            <select id="wxid" name="wxid" class="form-control">
                <!--# for(o in wxList){
                #-->
                <option value="${o.id}"<!--#if(o.id==wxid){#-->selected<!--#}#-->>${o.appname}</option>
                <!--#
                } #-->
            </select>
        </div>
    </div>
    <div class="pull-right">
        <div class="btn-group tool-button">
            <button class="btn btn-primary navbar-btn" onclick="sort()"> ${msg['wx.menu.column.savesort']}</button>
        </div>
        <div class="btn-group tool-button">
            <button class="btn btn-primary navbar-btn" onclick="complete()"><i class="ti-share"></i> ${msg['wx.menu.column.pushedtowechat']}</button>
        </div>
    </div>
</header>
<div class="modal-body no-p">
    <div class="panel">
        <div class="panel-heading no-b">
        </div>
        <div class="panel-body" style="padding-top: 30px;">

            <div class="cf nestable-lists">
                <div class="dd" id="nestable3">
                    <!--# if(!isEmpty(firstMenus)){ #-->
                    <ol class="dd-list">
                        <!--# for(firstMenu in firstMenus){ #-->
                        <li class="dd-item dd3-item" data-id="${firstMenu.id}">
                            <div class="dd-handle dd3-handle">Drag</div>
                            <div class="dd3-content">${firstMenu.menuName!} <span style="color: deepskyblue"> ${firstMenu.menuKey!}${firstMenu.url!}</span>
                                <div class="btn-group pull-right"><button type="button" class="btn btn-default btn-xs dropdown-toggle" data-toggle="dropdown">
                                    <i class="ti-settings"></i> <span class="ti-angle-down"></span></button><ul class="dropdown-menu" role="menu">
                                    <li><a href="${base}/platform/wx/conf/menu/edit/${firstMenu.id!}" data-pjax>${msg['wx.menu.column.edit']}</a></li>
                                    <li><a href="javascript:;" onclick="del('${firstMenu.id!}')">${msg['wx.menu.column.delete']}</a></li>
                                </ul></div>
                            </div>
                            <!--# if(!isEmpty(@secondMenus.get(firstMenu.path))){ #-->
                            <ol class="dd-list">
                                <!--# for(secondMenu in @secondMenus.get(firstMenu.path)){  #-->
                                <li class="dd-item dd3-item" data-id="${secondMenu.id}">
                                    <div class="dd-handle dd3-handle">Drag</div>
                                    <div class="dd3-content">${secondMenu.menuName!}<span style="color: deepskyblue"> ${secondMenu.menuKey!}${secondMenu.url!}</span>
                                        <div class="btn-group pull-right"><button type="button" class="btn btn-default btn-xs dropdown-toggle" data-toggle="dropdown">
                                            <i class="ti-settings"></i> <span class="ti-angle-down"></span></button><ul class="dropdown-menu" role="menu">
                                            <li><a href="${base}/platform/wx/conf/menu/edit/${secondMenu.id!}" data-pjax>${msg['wx.menu.column.edit']}</a></li>
                                            <li><a href="javascript:;" onclick="del('${secondMenu.id!}')">${msg['wx.menu.column.delete']}</a></li>
                                        </ul></div>
                                    </div>
                                </li>
                                <!--# }#-->
                            </ol>
                            <!--# } #-->
                        </li>
                        <!--# } #-->

                    </ol>
                    <!--#}else{#-->
                    <ol class="dd-list" style="padding-top: 10px;">${msg['wx.menu.column.notconfigured']}</ol>
                    <!--#}#-->
                </div>
            </div>

        </div>
    </div>
</div>
<div id="dialogDelete" class="modal fade bs-modal-sm" tabindex="-2" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title">${msg['wx.menu.column.deletemenu']}</h4>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div class="col-xs-12">
                       ${msg['wx.menu.column.text']} 
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">${msg['wx.menu.column.cancel']}</button>
                <button id="ok" type="button" class="btn btn-primary" data-loading-text="${msg['wx.menu.column.nowdelete']}">${msg['wx.menu.column.soure']}</button>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    function del(id){
        var dialog = $("#dialogDelete");
        dialog.modal("show");
        dialog.find("#ok").unbind("click");
        dialog.find("#ok").bind("click", function(event){
            var btn = $(this);
            btn.button("loading");
            $.post("${base}/platform/wx/conf/menu/delete/"+id,{},function(data){
                //重置按钮状态，关闭提示框
                dialog.modal("hide");
                if(data.code==0){
                    Toast.success(data.msg);
                    window.location.reload();
                }else{
                    Toast.error(data.msg);
                }
                btn.button("reset");
            },"json");
        });
    }
    var ids=[];
    function getId(ob){
        $.each(ob,function(i,o){
            ids.push(o.id);
            if(o.children){
                getId(o.children);
            }
        });
    }
    function sort(){
        ids=[];
        getId($("#nestable3").nestable('serialize'));
        $.post("${base}/platform/wx/conf/menu/sortDo", {wxid:'${wxid}',ids: ids.toString()}, function (data) {
            if (data.code == 0) {
                Toast.success(data.msg);
            } else {
                Toast.error(data.msg);
            }
        }, "json");
    }
    function complete(){
        sublime.showLoadingbar($(".main-content"));
        $.post("${base}/platform/wx/conf/menu/pushMenu/${wxid}", {}, function (data) {
            sublime.closeLoadingbar($(".main-content"));
            if (data.code == 0) {
                Toast.success(data.msg);

            } else {
                Toast.error(data.msg);
            }
        }, "json");
    }

    $(function () {
        $("#nestable3").nestable();
        $("#wxid").on("change",function(){
            $("#_reload").attr("href","${base}/platform/wx/conf/menu/index/"+$(this).val());
            $("#_reload").trigger("click");
        });
    });

</script>

<!--#}#-->
